import time

from DrissionPage import ChromiumPage

def kgj_html_page(port,file):
    page = ChromiumPage(addr_or_opts='127.0.0.1:' + port)
    xpath = '//*[@id="app"]/div[3]/div[2]/div'
    html_div = page.ele('xpath:' + xpath)
    if html_div:
        with open(file, "w", encoding='utf-8') as f:
            f.write(html_div.html)

    page.scroll.to_bottom()# 滚动最底部


def all_html_page(port):
    page = ChromiumPage(addr_or_opts='127.0.0.1:' + port)
    page.scroll.to_bottom()# 滚动最底部
    time.sleep(1)
    
    with open('page.html', "w", encoding='utf-8') as f:
        f.write(page.html)
    with open('page.url', "w", encoding='utf-8') as f:
        f.write(page.url)


import argparse

# 1. 定义命令行解析器对象
parser = argparse.ArgumentParser(description='调用参数')

# 2. 添加命令行参数
parser.add_argument('--port', type=str, default='9333')

parser.add_argument('--file', type=str, default=None)

# 3. 获取参数值
args = parser.parse_args()
port = args.port
file = args.file

# kgj_html_page(port,file)
all_html_page(port)







